import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:series_play/widget/app_color.dart';
import 'package:series_play/widget/app_text.dart';

class AppButton extends StatelessWidget {
  const AppButton(
    this.name, {
    this.height,
    this.fontSize,
    this.color,
    this.leftAction,
    this.rightAction,
    this.onTap,
    this.margin,
    this.isGradient = true,
    this.isSplash = true,
    super.key,
  });

  final String name;
  final double? height;
  final double? fontSize;
  final Color? color;
  final Widget? leftAction;
  final Widget? rightAction;
  final EdgeInsetsGeometry? margin;
  final VoidCallback? onTap;
  final bool isGradient;
  final bool isSplash;

  @override
  Widget build(BuildContext context) {
    Widget child = Container(
      height: (height ?? 36).w,
      margin: margin,
      decoration: BoxDecoration(
        gradient: isGradient
            ? LinearGradient(
                colors: [const Color(0xFFD90F52), const Color(0xFFE75E29)],
              )
            : null,
        color: !isGradient ? (color ?? AppColor.primary) : null,
        borderRadius: BorderRadius.circular(6).r,
      ),
      alignment: Alignment.center,
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          leftAction ?? Container(),
          AppText(name, color: Colors.white, fontSize: fontSize),
          rightAction ?? Container(),
        ],
      ),
    );
    return GestureDetector(
      onTap: onTap,
      behavior: HitTestBehavior.translucent,
      child: child,
    );
  }

  /// 普通小按钮
  ///
  /// 删除、取消、确定
  factory AppButton.normal({
    required String name,
    double? height,
    double? fontSize,
    Color? color,
    VoidCallback? onTap,
  }) {
    return AppButton(
      name,
      height: height,
      fontSize: fontSize ?? 14,
      onTap: onTap,
      isGradient: false,
      color: color ?? const Color(0xFF393D45),
    );
  }
}
